import cityCascader from "../../../component/cityCascader/index.vue";
export default {
  props:['totalNum'],
  data() {
    return {
		refundData:{},
	  refundDialog:false,//提现窗口
	  reson:'',//提现失败原因
      list: [],
      title: "申请时间段",
      current: 1,
      tabs: [{
          label: "待审核",
          value: 0,
          order: 1
        },
        {
          label: "银行受理中",
          value: 0,
          order: 4
        },
        {
          label: "提现成功",
          value: 0,
          order: 2
        },
        {
          label: "提现失败",
          value: 0,
          order: 3
        }
      ],
      dialogTableVisible: false,
      radio: "1", //提现状态
      textarea: "",
      bankInfo: ['中国银行', '中国工商银行', '中国农业银行', '中国邮政储蓄银行'], // 银行类型
      waiteList: [],
      // {
      //   nickanme: '',
      //   telnum: '',
      //   bankname: '',
      //   usenum: '',
      //   outintegral: '',
      //   inserdate: ''
      // }
      outid: '', //待审核id
      // 页码数
      Page: {
        total: 20,
        pageNum: 1,
        pageSize: 10
      },
      companyInfo: {},
	  departshow:false,
      searchData: {
        createTime: "",
        // regions: "",
        citys: [],
        province: "", //省份编码
        city: '', //城市编码
        area: '', //区域编码
        begintime: '',
        endtime: ''

      },
      level: '0',
      addressOptions: [],
      global: {},
      warnDialogVisible: false,
      reportType: "",
      reportContent: "",
      reportId: "",
      optShowOne: false,
      optShowTwo: false,
      // optShow: false
	  switchValue: true						//开关
    }
  },
  components: {
    cityCascader
  },
  created() {
	  if(localStorage.getItem('department')=='提现二部'){
		  this.departshow=true
	  }
    this.global = this.GLOBAL;
    let department = JSON.parse(localStorage.getItem('userinfo')).department;
    if (department == "提现一部") {
      this.optShowOne = true;
      this.optShowTwo = false
    } else if (department == "提现二部") {
      this.optShowOne = false;
      this.optShowTwo = true
    }
    this.waiteCash();
    this.getAuthority();
	this.searchSwitch();
	 
  },
  methods: {
	  //拒绝提现理由
	  subRefund(){
		  
		  if(this.reson==''){
			  return this.$message.error('请输入退款理由！！！')
		  }
	  
		  let data = {
			  auditorid: localStorage.getItem('userid'), 
			  id:this.refundData.outid,//订单号
			  money: this.refundData.outintegral, //提现金额
			  note: this.reson, //备注
			  telnum:this.refundData.telnum //提现人手机号
		  }
		  this.$ceshiAxios.post('/v1/common/updateOutStatus',data).then(res=>{
			  if(res.data.code==1){
				  this.$message.success('操作成功');
					 this.successCash(1)
			  }else {
				  this.$message.error(res.data.message)
			  }
			   this.refundDialog = false
		  })
	  },
	  refundBtn(data){
		 this.refundDialog = true
		 this.refundData=data
		  console.log(data);
	  },
    getAuthority() {
      let userinfo = localStorage.getItem('userinfo');
      userinfo = JSON.parse(userinfo);
      this.level = userinfo.level;
      this.searchData.province = +userinfo.province || '';
      this.searchData.city = +userinfo.city || '';
      this.searchData.area = +userinfo.area || '';
      this.searchData.citys = [];
      this.searchData.citys.push(+userinfo.province);
      this.searchData.citys.push(+userinfo.city);
      this.searchData.citys.push(+userinfo.area);
    },


    clickTab(item) {
      this.searchData.begintime = "";
      this.searchData.endtime = "";
      this.searchData.citys = [];
      this.searchData.province = "";
      this.searchData.city = "";
      this.searchData.area = "";
      switch (item.order) {
        case 1:
        case 4:
          this.current = item.order;
          this.title = "申请时间段"
          this.waiteCash();
          break;
        case 2:

          this.current = item.order;
          this.title = "审批时间段"
          this.successCash();
          break;
        case 3:
          this.current = item.order;
          this.title = "审批时间段"
          this.failCash();
          break;
      }
    },
    compareTime() {
      if (this.searchData.begintime && this.searchData.endtime && Date.parse(this.searchData.begintime) > Date.parse(this.searchData.endtime)) {
        this.$message({
          message: "结束时间不能早于开始时间",
          type: "warning"
        });
        return false;
      } else {
        return true;
      }
    },
    // 待审核
    waiteCash(p) {
      let currentStatus = this.current - 1;
      let obj = {
        pagenum: p || 1,
        status: currentStatus,
        pagesize: this.Page.pageSize,
        province: this.searchData.province, //省份编码
        city: this.searchData.city, //城市编码
        area: this.searchData.area, //区域编码
        begintime: this.searchData.begintime,
        endtime: this.searchData.endtime,
      }
      if (this.compareTime()) {
        this.$axios.post('/app/v1/platform/member/integerOutList', obj).then(resp => {
		  console.log(resp);
          if (resp.data.code === 1) {
            this.waiteList = resp.data.data.list;
			this.$emit('update:totalNum',resp.data.data.totalnum);
            this.tabs[0].value = resp.data.data.totalnum; //总数
            this.Page.total = parseInt(resp.data.data.totalnum); //总数
            this.Page.pageNum = parseInt(resp.data.data.pagenum); //第一页
            // this.Page.pageSize = parseInt(resp.data.data.pagecount); //当前页显示条数
            for (let i = 0; i < resp.data.data.list.length; i++) {
              this.waiteList[i].bankname = this.bankInfo[resp.data.data.list[i].banktype];
            }
            this.Page.pageNum = p || 1;
          }
        })
      }
    },
    // 提现成功
    successCash(p) {

      let obj = {
        pagenum: p || 1,
        status: "1",
        pagesize: this.Page.pageSize,
        province: this.searchData.province, //省份编码
        city: this.searchData.city, //城市编码
        area: this.searchData.area, //区域编码
        begintime: this.searchData.begintime,
        endtime: this.searchData.endtime,
      }
      if (this.compareTime()) {
        this.$axios.post('/app/v1/platform/member/integerOutList', obj).then(resp => {
		  console.log(resp);
          if (resp.data.code === 1) {
            this.waiteList = resp.data.data.list;
            this.tabs[1].value = resp.data.data.totalnum; //总数
            this.Page.total = parseInt(resp.data.data.totalnum); //总数
            this.Page.pageNum = parseInt(resp.data.data.pagenum); //第一页
            // this.Page.pageSize = parseInt(resp.data.data.pagecount); //当前页显示条数
            for (let i = 0; i < resp.data.data.list.length; i++) {
              this.waiteList[i].bankname = this.bankInfo[resp.data.data.list[i].banktype];
            }
          } else {
            this.$message("网络异常！");
          }
        })
      }
    },
    // 提现失败
    failCash(p) {
      let obj = {
        pagenum: p || 1,
        status: '2',
        pagesize: this.Page.pageSize,
        province: this.searchData.province, //省份编码
        city: this.searchData.city, //城市编码
        area: this.searchData.area, //区域编码
        begintime: this.searchData.begintime,
        endtime: this.searchData.endtime,
      }
      if (this.compareTime()) {
        this.$axios.post('/app/v1/platform/member/integerOutList', obj).then(resp => {
          if (resp.data.code === 1) {
			console.log(resp.data.data);
            this.waiteList = resp.data.data.list;
            this.tabs[2].value = resp.data.data.totalnum; //总数
            this.Page.total = parseInt(resp.data.data.totalnum); //总数
            this.Page.pageNum = parseInt(resp.data.data.pagenum); //第一页
            // this.Page.pageSize = parseInt(resp.data.data.pagecount); //当前页显示条数
            for (let i = 0; i < resp.data.data.list.length; i++) {
              this.waiteList[i].bankname = this.bankInfo[resp.data.data.list[i].banktype];
            }
          } else {
            this.$message("网络异常！");
          }
        })
      }
    },
    PageCurrentChange(p) {
      if (this.current === 1 || this.current === 4) {
        this.waiteCash(p);
      } else if (this.current === 2) {
        this.successCash(p);
      } else if (this.current === 3) {
        this.failCash(p);
      }
    },
    // 审批对话框
    openDialog(row) {
      this.dialogTableVisible = true;
      this.outid = row.outid;
      this.radio = '1';
      this.textarea = '';
      this.companyInfo = row;
    },
    //取消提现
    concelCash() {
      this.dialogTableVisible = false;
    },
    resultChange(r) {
      if (r === '1') this.textarea = '';
    },
    // 确定提现
    confirmCash() {
      if (this.textarea.trim() === "" && this.radio === "2") {
        this.$message({
          message: "请填写不通过原因!",
          type: "warning"
        });
        return;
      }
      let operation = this.radio === "1" ? "通过" : "驳回";
      this.$confirm(`此操作将${operation}该提现, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let obj = {
          outid: this.outid,
          status: this.radio,
          paymentdate: '',
          note: this.textarea
        }
        this.$axios.post("/app/v1/platform/member/integerOutResult", obj).then(resp => {
          if (resp.data.code === 1) {
            this.dialogTableVisible = false;
            this.waiteCash();
          } else {
            this.$message({
              message: resp.data.message,
              type: "error"
            });
            this.dialogTableVisible = false;
            this.waiteCash();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'warning',
          message: '已取消删除'
        });
      });
    },

    //上报
    toReport(r, type) {
      this.warnDialogVisible = true;
      this.reportType = type;
      this.reportContent = '';
      this.reportId = r.outid;
    },
    closeWarnDialog() {
      this.reportContent = "";
    },
    confirmReport() {
      this.reportAjax();
    },
    //上报请求
    reportAjax() {
      let data = {
        id: this.reportId,
        reporttype: this.reportType,
        content: this.reportContent
      }
      if (!this.reportContent) {
        this.$message({
          type: "warning",
          message: "上报内容不能为空!"
        });
        return;
      }
      this.$axios
        .post("/app/v1/platform/unusual/reportSubmit", data)
        .then(res => {
          if (res.data.message === "success.") {
            this.warnDialogVisible = false;
            this.$message({
              type: "success",
              message: "操作成功!"
            });
			this.waiteCash()
          } else {
            this.warnDialogVisible = false;
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
        });
    },
	// 查看按钮是否开启
	searchSwitch(){
		this.$axios.post('/app/v1/NoRead/selectOpenWithdraw').then(res => {
			if(res.data.code === 1){
				if(res.data.data == 1){
					this.switchValue = true;
				}else{
					this.switchValue = false;
				}
			}
		})
	},
	// IOS提现按钮事件
	subSwitch(){
		let openWithdraw = '';
		if(this.switchValue === true){
			openWithdraw = '1';
		}else{
			openWithdraw = '0';
		}
		this.$axios.post('/app/v1/NoRead/updateOpenWithdraw',{openWithdraw: openWithdraw}).then(res => {
			if(res.data.code === 1){
				this.$message({
					message: '操作成功!',
					type: 'success'
				})
			}
		})
	},

    //会员提现申请导入接口
    // uploadFile(event) {
    //   let config = {
    //     headers: {
    //       "Content-Type": "multipart/form-data" //添加请求头
    //     }
    //   };
    //   let uploadFile = event.target.files[0]; // 文件对象
    //   let filetype = uploadFile.name.split(".")[1]; // 文件后缀名
    //   if (filetype !== "xlsx") {
    //     this.$message({
    //       type: "warning",
    //       message: "请上传excel文件!"
    //     });
    //     return;
    //   }
    //   let param = new FormData(); // 创建form对象
    //   // let filepermission = "1";
    //   param.append("filecontent", uploadFile);
    //   // param.append("filepermission", filepermission);
    //   this.$axios.post("/app/v1/platform/statistic/personaWithdrawalImport", param, config).then(res => {
    //     if (res.data.code === 1) {
    //       this.$message({
    //         type: "success",
    //         message: "导入成功!"
    //       });
    //     } else {
    //       this.$message({
    //         type: "warning",
    //         message: "文件上传失败!"
    //       });
    //     }
    //   });
    // },


    //提现申请列表导出接口
    // exportAllAjax() {
    //   this.$axios({
    //     method: 'post',
    //     url: '/app/v1/platform/statistic/withdrawalOut',
    //     data: {
    //       type: 1
    //     },
    //     responseType: 'blob'
    //   }).then(res => {
    //     this.download(res)
    //   }).catch((error) => {
    //     this.$message({
    //       message: '导出失败,请重新操作',
    //       type: 'warning'
    //     });
    //   })


    // },

    // download(res) {
    //   if (!res) {
    //     return
    //   }
    //   let bob = new Blob([res.data]);
    //   let fileName = (res.headers['content-disposition']).split('=')[1];
    //   fileName = decodeURI(fileName)
    //   let url = window.URL.createObjectURL(bob)
    //   let link = document.createElement('a')
    //   link.style.display = 'none'
    //   link.href = url
    //   link.setAttribute('download', fileName)
    //   document.body.appendChild(link)
    //   link.click()
    // },

    //点击导出
    // exportAll() {
    //   this.exportAllAjax();
    // },

    // 选择城市
    handleCityChange(val) {
      this.searchData.citys = val;
      this.searchData.province = val[0];
      this.searchData.city = val[1];
      this.searchData.area = val[2];
    },

    handleSizeChange(val) {
      this.Page.pageSize = val;
      if (this.current === 1 || this.current === 4) {
        this.waiteCash();
      } else if (this.current === 2) {
        this.successCash();
      } else if (this.current === 3) {
        this.failCash();
      }
    },
    //查询
    SearchInfo() {
      if (this.current === 1 || this.current === 4) {
        this.waiteCash();
      } else if (this.current === 2) {
        this.successCash();
      } else if (this.current === 3) {
        this.failCash();
      }
    }
  }
}